home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 February / CHIPCD_02_2002.iso / Internet / Macromedia ColdFusion Server 5 / coldfusion-50-win-us.exe / data1.cab / Examples / CFDOCS / snippets / arraysum.cfm < prev    next >
Encoding:
Text File  |  2001-06-13  |  1.2 KB  |  44 lines

  1. <!--- This example shows the use of ArraySum --->
  2. <HTML>
  3. <HEAD>
  4. <TITLE>ArraySum Example</TITLE>
  5. </HEAD>
  6.  
  7. <BASEFONT FACE="Arial, Helvetica" SIZE=2>
  8. <BODY  bgcolor="#FFFFD5">
  9.  
  10. <H3>ArraySum Example</H3>
  11. <P>
  12. If this example doesn't run or returns 
  13. erroneous results, you may need to 
  14. either create the snippets collection
  15. (using the CFCOLLECTION example) or populate
  16. the snippets collection (using the CFINDEX example).
  17. <HR>
  18. <!--- create an array --->
  19. <CFSET myNumberArray = ArrayNew(1)>
  20. <!--- run a standard search --->
  21.  <CFSEARCH NAME="SearchSnippets"
  22.         COLLECTION="snippets"
  23.         TYPE="simple"
  24.         CRITERIA="Array*">
  25. <!--- set a temp variable --->
  26. <CFSET temp = 1>
  27. <!--- output the results of the search --->
  28. <CFOUTPUT QUERY="SearchSnippets">
  29.     <CFSET myNumberArray[temp] = score>
  30. <CFSET temp = temp + 1>
  31. </CFOUTPUT>
  32. <!--- use ArrayAvg to get the average score --->
  33. <P>The average score for your search on the term
  34. "Array*" in the collection "Snippets" is 
  35. <CFOUTPUT>
  36. #ArrayAvg(myNumberArray)# for
  37. #SearchSnippets.RecordCount# "hits"<BR>
  38. <P>The sum of the elements in the array is
  39. #ArraySum(myNumberArray)#
  40. </CFOUTPUT>
  41.  
  42. </BODY>
  43. </HTML>       
  44.